﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Interfaces.Inherited_Interfaces;
using Interfaces.General_Interfaces;
using Views.Add_Views;
using Views.Delete_Views;
using Views.Status_Views;
using Presenters.General_Presenters;
using Model.Domain_Model;
using Extenions.DataGridViewSection;

namespace Views.General_Views
{
    public partial class ClientsView : UserControl, IClientsView
    {
        ClientsViewPresenter presenter = null;

        public ClientsView()
        {
            InitializeComponent();
            presenter = new ClientsViewPresenter(this);
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            presenter.GetClientList();
        }

        private void toolStripLabel1_Click(object sender, EventArgs e)
        {
            presenter.DisplayView(new ClientAddView());
        }

        IList<Client> IClientsView.clientList
        {
            get
            {
                return (List<Client>)clientList.DataSource;
            }
            set
            {
                clientList.DataSource = value;
            }
        }

        void IError.ShowError()
        {
            presenter.ShowError(new ErrorView());
        }

        void ISuccess.ShowSuccess()
        {
            presenter.ShowSuccess(new SuccessView());
        }

        private void toolStripLabel2_Click(object sender, EventArgs e)
        {
            presenter.DisplayView(new ClientUpdateView());
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            presenter.selectedClient = (Client)clientList.CurrentRow.DataBoundItem;
        }

        T IView.ReturnView<T>()
        {
            return (T)((object)this);
        }

        private void toolStripLabel3_Click(object sender, EventArgs e)
        {
            presenter.DisplayView(new ClientDeleteView());
        }

        private void label6_Click(object sender, EventArgs e)
        {
            presenter.GetClientList();
        }

        void IGrid.HideColumn()
        {
            clientList.Columns["descriptionClient"].Visible = false;
            clientList.Columns["isProtected"].Visible = false;
            clientList.Columns["dateInsert"].Visible = false;
        }

        void IGrid.MappingColumnName()
        {
            clientList.Columns["nameCorporation"].HeaderCell.Value = "Firma";
            clientList.Columns["nameClient"].HeaderCell.Value = "Imię klienta";
            clientList.Columns["surnameClient"].HeaderCell.Value = "Nazwisko klienta";
            clientList.Columns["inventedName"].HeaderCell.Value = "Nazwa własna";
            clientList.Columns["email"].HeaderCell.Value = "E-mail";
            clientList.Columns["phoneNumber"].HeaderCell.Value = "Numer telefonu";
            clientList.Columns["idClient"].HeaderCell.Value = "Id";
        }

        void IGrid.ResizeColumn()
        {
            clientList.Columns["idClient"].Width = 70;
            clientList.Columns["email"].Width = 200;
            clientList.Columns["phoneNumber"].Width = 130;
            clientList.Columns["nameClient"].Width = 130;
            clientList.Columns["surnameClient"].Width = 140;
            clientList.Columns["inventedName"].Width = 120;
        }


        string IClientsView.inventedName
        {
            get
            {
                return inventedNameFiltr.Text;
            }
            set
            {
                inventedNameFiltr.Text = value as string;
            }
        }

        string IClientsView.nameClient
        {
            get
            {
                return nameClientFiltr.Text;
            }
            set
            {
                nameClientFiltr.Text = value as string;
            }
        }

        string IClientsView.nameCorporation
        {
            get
            {
                return nameCorporationFiltr.Text;
            }
            set
            {
                nameCorporationFiltr.Text = value as string;
            }
        }

        string IClientsView.surnameClient
        {
            get
            {
                return surnameClientFiltr.Text;
            }
            set
            {
                surnameClientFiltr.Text = value as string;
            }
        }

        private void label5_Click(object sender, EventArgs e)
        {
            presenter.SearchClient();
        }
    }
}
